/*
 * Created by VSCode
 * User: 范在英
 * Date: 2018/11/21
 * Time: 18:53
 * feature: 控制页面按钮点击频率
 * use: <button v-intervalclick='{func:执行方法,time:间隔时间(毫秒数),...执行方法所需要的参数}'>点击</button>
 * use: main.js中将此引入
 */
// import Vue from 'vue';

// Vue.directive('intervalClick', function(el,binding){
//     let openDelay=false;
//     el.onclick = function(e){
//         if(openDelay)return;
//         openDelay=!openDelay;
//         if (!binding.value) {
//             console.log("未传入Value数据！");
//             return;
//         }
//         let func = binding.value['func'];
//         let time = binding.value['time'];
//         if(typeof time !=='number'){
//             console.log("传入等待时间错误");
//             return;
//         }
//         let args=[];
//         for (const key in binding.value) {
//             if (binding.value.hasOwnProperty(key)) {
//                 if(key==='func'||key==='time')continue;
//                 args.push(binding.value[key])
//             }
//         }
//         setTimeout(() => {
//             openDelay=!openDelay; 
//         }, time);
//         func(...args);
//     }
// })

// export default Vue

// 第二种方式  
// 使用方式同上
// 引用方式 main.js 
// import intervalClick from '../../javascript/intervalClick';
// Vue.directive('intervalClick', intervalClick);
let openDelay = false;
export default function(el,binding){
    // let openDelay = false;
    el.onclick = function(e){
        if(openDelay)return;
        openDelay =! openDelay;
        if (!binding.value) {
            console.log("未传入Value数据！");
            return;
        }
        let func = binding.value['func'];
        let time = binding.value['time'];
        if(typeof time !== 'number'){
            console.log("传入等待时间错误");
            return;
        }
        let args=[];
        for (const key in binding.value) {
            if (binding.value.hasOwnProperty(key)) {
                if(key==='func'||key==='time')continue;
                args.push(binding.value[key])
            }
        }
        setTimeout(() => {
            openDelay =! openDelay; 
        }, time);
        func(...args);
    }
}

